-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
43 lines (33 loc) · 1.13 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n, m, p;
n = sc.nextInt();
for (int i = 0; i < n; i++) {
m = sc.nextInt();
String[] produtos = new String[m];
double[] precos = new double[m];
double total = 0d;
for (int j = 0; j < m; j++) {
produtos[j] = sc.next();
precos[j] = sc.nextDouble();
}
p = sc.nextInt();
String[] produtosComprados = new String[p];
int[] quantidades = new int[p];
for (int j = 0; j < p; j++) {
produtosComprados[j] = sc.next();
quantidades[j] = sc.nextInt();
for (int k = 0; k < m; k++) {
if (produtosComprados[j].equals(produtos[k])) {
total += precos[k] * quantidades[j];
}
}
}
System.out.printf("R$ %.2f\n", total);
}
sc.close();
}
}